package com.clever.mall.controller;

import com.clever.mall.commons.result.BaseResult;
import com.clever.mall.service.SearchService;
import com.clever.mall.vo.SearchVo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Resource
    SearchService searchService;

    //查找所有用户的搜索数高的前8条
    @RequestMapping("/findAllSearch")
    public BaseResult findAllSearch(){
        List<SearchVo> allSearch = searchService.findAllSearch();
        return BaseResult.success(allSearch);
    }

    //超找用户的搜索关键字前8条
    @RequestMapping("/findByUserId")
    public BaseResult findByUserId(@NotNull int userId){
        List<SearchVo> byUserId = searchService.findByUserId(userId);
        return BaseResult.success(byUserId);
    }

    //删除用户的搜索记录
    @RequestMapping("/deleteByUserId")
    public BaseResult deleteByUserId(@NotNull int userId){
        int i = searchService.deleteByUserId(userId);
        return BaseResult.success(i);
    }
}
